#ifndef UTILS_STRING_H
#define UTILS_STRING_H

#include <string>
#include <cstdio>


/** @file utils/stringutils.h
 * @ingroup Utils
 * @brief Utilities for string manipulation.
 */

/** @addtogroup Utils */
/*@{*/

///Returns a "close bracket" character opposite c
char CloseBracket(char c);

///Turns the string into lower/uppercase
void Lowercase(char* str);
void Uppercase(char* str);
void Lowercase(std::string& str);
void Uppercase(std::string& str);

//strips whitespace from str
std::string Strip(const std::string& str);
std::string LStrip(const std::string& str);
std::string RStrip(const std::string& str);

///Replace all instances of strfind with strreplace in str
int ReplaceAll(std::string& str,const char* strfind,const char* strreplace);

bool IsValidCToken(const char* str);
bool IsValidInteger(const char* str);
bool IsValidFloat(const char* str);

///Detects a pattern in str = [prefix][digits][suffix].
///Returns the number specified by [digits], or -1 if no such pattern is found.
int DetectNumericalPattern(const char* str,char prefix[],char suffix[],int& numDigits);

//For a string in the pattern XXXX####XXXX, increments the #### part.
//The number of digits can be 1-4.  For a string with no digits,
//leaves the string unchanged.
void IncrementStringDigits(char* str);
void IncrementStringDigits(std::string& str);

std::string ToBase64(const std::string& in);
std::string FromBase64(const std::string& in);

///Dos-unix endline conversion
int LengthWithDOSEndlines(const char* str);
bool EndlinesToDOS(const char* str,char* out,int max);
bool EndlinesFromDOS(const char* str,char* out,int max);
void EndlinesToDOS(std::string& str);
void EndlinesFromDOS(std::string& str);

///Returns pointer to "ext" for str="filename.ext"
const char* FileExtension (const char* str);
///Replaces the file extension of str with ext, or concatenates .ext onto str
void ChangeFileExtension (char* str, const char* ext);
///Returns "file.ext" for the str="dir1/dir2/.../file.ext"
const char* GetFileName(const char* str);
///Extracts the path from str (formatted as above) into buf
void GetFilePath(const char* str, char* buf);
///Removes the file extension of str
void StripExtension(char* str);

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
void ToWideChar(const char* str, WCHAR* buf, int maxBuf);
#endif //WIN32

/*@}*/

#endif
